package com.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.system.entity.Role;
import com.system.mapper.RoleMapper;
import com.system.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hujunwei
 * @since 2021-11-22
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addRole() {
        Role role = new Role();
        role.setName("老师");
        role.setParentId(0L);
        baseMapper.insert(role);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addRoleException() {
        Role role = new Role();
        role.setName("老师EXCEPTION");
        role.setParentId(0L);
        baseMapper.insert(role);
        throw new RuntimeException("新增角色老师失败!");
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addRoleNew() {
        Role role = new Role();
        role.setName("老师");
        role.setParentId(0L);
        baseMapper.insert(role);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addRoleExceptionNew() {
        Role role = new Role();
        role.setName("老师EXCEPTION");
        role.setParentId(0L);
        baseMapper.insert(role);
        throw new RuntimeException("新增角色老师失败!");
    }
}
